package org.light.jpa.shiroauth;

import java.util.ArrayList;
import java.util.List;

import org.light.core.Verb;
import org.light.core.Writeable;
import org.light.domain.Domain;
import org.light.domain.Dropdown;
import org.light.domain.Field;
import org.light.domain.JavascriptBlock;
import org.light.domain.JavascriptMethod;
import org.light.domain.Method;
import org.light.domain.Signature;
import org.light.domain.Statement;
import org.light.domain.StatementList;
import org.light.domain.Type;
import org.light.domain.Var;
import org.light.easyui.EasyUIPositions;
import org.light.exception.ValidateException;
import org.light.generator.NamedStatementGenerator;
import org.light.generator.NamedStatementListGenerator;
import org.light.jpa.core.JpqlReflector;
import org.light.utils.InterVarUtil;
import org.light.utils.StringUtil;
import org.light.utils.TableStringUtil;
import org.light.utils.WriteableUtil;

public class GetPasswordUser extends org.light.shiroauth.verb.GetPasswordUser {

	@Override
	public Method generateDaoImplMethod() throws Exception {
		return null;
	}	

	@Override
	public Method generateDaoMethodDefinition() throws Exception {
		if (this.denied) return null;
		else {
			Method method = new Method();
			method.setStandardName("getPassword"+StringUtil.capFirst(this.domain.getStandardName()));
			method.setReturnType(new Type("String"));
			method.setThrowException(true);
			method.addAdditionalImport(this.domain.getPackageToken()+ "."+this.domain.getDomainSuffix()+"."+this.domain.getCapFirstDomainNameWithSuffix());			
			method.addSignature(new Signature(1, this.domain.findFieldByFixedName("userName").getLowerFirstFieldName(), this.domain.findFieldByFixedName("userName").getFieldRawType(),this.domain.getType().getPackageToken()));
			method.addMetaData("Query(\""+JpqlReflector.generateGetPasswordStatement(domain)+"\")");
			return method;
		}
	}

	@Override
	public Method generateServiceMethodDefinition() throws Exception {
		if (this.denied) return null;
		else {
			Method method = new Method();
			method.setStandardName("getPassword"+StringUtil.capFirst(this.domain.getStandardName()));
			method.setReturnType(new Type("String"));
			method.setThrowException(true);
			method.addAdditionalImport("java.util.List");
			method.addAdditionalImport(this.domain.getPackageToken()+ "."+this.domain.getDomainSuffix()+"."+this.domain.getCapFirstDomainNameWithSuffix());
			method.addSignature(new Signature(1, this.domain.findFieldByFixedName("userName").getLowerFirstFieldName(), this.domain.findFieldByFixedName("userName").getFieldRawType(),this.domain.getType().getPackageToken()));
			return method;
		}
	}

	@Override
	public Method generateServiceImplMethod() throws Exception  {
		if (this.denied) return null;
		else {
			Method method = new Method();
			method.setStandardName("getPassword"+StringUtil.capFirst(this.domain.getStandardName()));
			method.setReturnType(new Type("String"));
			method.setThrowException(true);
			method.addAdditionalImport("java.util.List");
			method.addAdditionalImport("org.springframework.transaction.annotation.Transactional");
			method.addAdditionalImport(this.domain.getPackageToken()+ "."+this.domain.getDomainSuffix()+"."+this.domain.getCapFirstDomainNameWithSuffix());
			method.addAdditionalImport(this.domain.getPackageToken()+"."+this.domain.getDaoSuffix()+"."+this.domain.getStandardName()+"Dao");
			method.addAdditionalImport(this.domain.getPackageToken()+"."+this.domain.getServiceSuffix()+"."+this.domain.getStandardName()+"Service");
			method.addMetaData("Override");		
			
			method.addSignature(new Signature(1, this.domain.findFieldByFixedName("userName").getLowerFirstFieldName(), this.domain.findFieldByFixedName("userName").getFieldRawType(),this.domain.getType().getPackageToken()));
			List<Writeable> list = new ArrayList<Writeable>();
			list.add(new Statement(1000L,2, "return "+InterVarUtil.DB.dao.getVarName()+ ".getPassword"+domain.getStandardName()+"("+domain.findFieldByFixedName("userName").getLowerFirstFieldName()+");"));
			method.setMethodStatementList(WriteableUtil.merge(list));
			return method;
		}
	}

	public GetPasswordUser(){
		super();
		this.setLabel("获取用户密码");
	}
	
	public GetPasswordUser(Domain domain) throws ValidateException{
		super();
		this.domain = domain;
		this.denied = domain.isVerbDenied("GetPasswordUser");
		this.setVerbName("GetPassword"+StringUtil.capFirst(this.domain.getStandardName()));
		this.setLabel("获取用户密码");
		if  (domain.getLanguage().equalsIgnoreCase("english"))  this.setLabel("GetPasswordUser");
	}
}
